/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

/**
 * 表单验证规则
 */
export const rules = {
  select_required: {required: true, message: '请选择'},
  required: {required: true, message: '必填项'},
  text2_18: {min: 2, max: 18, message: '2-18个字符'},
  text2_32: {min: 2, max: 32, message: '2-32个字符'},
  text2_128: {min: 2, max: 128, message: '2-128个字符'},
  text2_18_char: {pattern:/^[0-9_a-zA-Z]{2,18}$/g, message: '2-18个字符，字母、数字、下划线'},
  text6_18_char: {pattern:/^[0-9_a-zA-Z]{6,18}$/g, message: '6-18个字符，字母、数字、下划线'},
  textMax_64: {max: 64, message: '最多64个字符'},
  textMax_128: {max: 128, message: '最多128个字符'},
  email: {type: 'email', message: '邮箱地址格式错误'},
  phone: {pattern: /^1[3456789]\d{9}$/, message: '手机号格式错误'},
  array_required: {type: 'array', required: true, message: '请至少选择一项'}
}